/*
 * TimeLog.java
 *
 * Created on July 10, 2006, 11:01 AM
 *
 * Brigham Young University - Idaho
 *
 */

package org.vcboard.model;

import java.text.*;
import java.util.*;

/**
 *
 * @author Josh VanderLinden
 */
public class TimeLog
{
   private int logId = -1;
   private LogDate clockIn = null;
   private LogDate clockOut = null;
   private boolean total = false;
   
   /** Creates a new instance of TimeLog */
   public TimeLog()
   {
   }
   
   public String getDate()
   {
      return getDate("E, dd MMM yyyy");
   }
   
   public String getDate(String format)
   {
      Format output = new SimpleDateFormat(format);
      Date input = new Date(clockIn.getTimeInMillis());
      return output.format(input);
   }
   
   public LogDate getClockIn()
   {
      return (isTotal() ? new LogDate() : clockIn);
   }
   
   public long getClockInTime()
   {
      return clockIn.getTimeInSeconds();
   }
   
   public long getClockInTimeMillis()
   {
      return clockIn.getTimeInMillis();
   }
   
   public void setClockIn(LogDate login)
   {
      this.clockIn = login;
   }
   
   public LogDate getClockOut()
   {
      return (isTotal() ? new LogDate() : clockOut);
   }
   
   public void setClockOut(LogDate logout)
   {
      this.clockOut = logout;
   }
   
   public long getClockOutTime()
   {
      return clockOut.getTimeInSeconds();
   }
   
   public long getClockOutTimeMillis()
   {
      return clockOut.getTimeInMillis();
   }
   
   public void setLogout(LogDate logout)
   {
      this.clockOut = logout;
   }
   
   public Duration getDuration()
   {
      Duration tmp = new Duration();
      
      if (!isTotal())
      {
         if (getClockOut() == null)
         {
            tmp.setDuration((System.currentTimeMillis() / 1000) - getClockInTime());
            //tmp.setDuration(-1);
         }
         else
         {
            tmp.setDuration(getClockOutTime() - getClockInTime());
         }
      }
      else
      {
         tmp.setDuration(-1);
      }
      
      return tmp;
   }

   public int getLogId()
   {
      return logId;
   }

   public void setLogId(int logId)
   {
      this.logId = logId;
   }

   public boolean isTotal()
   {
      return total;
   }

   public void setTotal(boolean total)
   {
      this.total = total;
   }
}
